import Notification from './notification.vue';
import Vue from 'vue'
import {DataNow} from '../../utils/index.js'

let $vm=null;
let notificationComponent;
Notification.newInstance = properties => {
  const _props = properties || {};

  const Instance = new Vue({
      render (h) {
          return h(Notification, {
              props: _props
          });
      }
  });

  const component = Instance.$mount();
  document.body.appendChild(component.$el);
  const notification = Instance.$children[0];
  // console.log(notification)
  return {
      notice (noticeProps) {
          notification.add(noticeProps);
      },
      remove (name) {
          notification.close(name);
      },
      component: notification,
      destroy (element) {
          notification.closeAll();
          setTimeout(function() {
              document.body.removeChild(document.getElementsByClassName(element)[0]);
          }, 500);
      }
  };
};
// export default Notification;
function getNotifiation(){
    notificationComponent=notificationComponent ||Notification.newInstance({
        prefixCls: 'iFast',
        styles: {
            top: `${top}px`,
            right: 0
        }
    });
    return notificationComponent;
}

function init(type,opction){
    let instance = getNotifiation();
    let name=opction.name||DataNow('_ifast'+opction.type);
    opction.name=name;
    instance.notice(opction)
}
export default {
    open (options) {
        return init('normal', options);
    },
    info (options) {
        return init('info', options);
    },
    success (options) {
        return init('success', options);
    },
    warning (options) {
        return init('warning', options);
    },
    error (options) {
        return init('error', options);
    },
    config (options) {
        if (options.top) {
            top = options.top;
        }
        if (options.duration || options.duration === 0) {
            defaultDuration = options.duration;
        }
    },
    close (name) {
        // if (name) {
        //     name = name.toString();
        //     if (noticeInstance) {
        //         noticeInstance.remove(name);
        //     }
        // } else {
        //     return false;
        // }
    },
    destroy () {
        let instance = getNoticeInstance();
        noticeInstance = null;
        instance.destroy('ivu-notice');
    }
}

// const noticeComponent ={
//   notice (noticeProps) {
//     if (!$vm) {
//         const notice= Vue.extend(notification)
    
//         $vm = new notice({
//             el: document.createElement('div')
//         });
//         document.body.appendChild($vm.$el);
//         const notification=$vm.$children[0];
//     }
//     console.log('add')
//   },
//   remove (name) {
//     console.log('remove')
//   },
//   destroy (element) {
//     console.log('destroy')
//   }
// }
// export default noticeComponent;